package com.oscar.ehome.utils.util;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;

/**
 * Created by oscar
 * author: MengWanhe
 * date: On 2017/6/27
 */

public class PermissionUtil {

    static boolean sdCardWritePermission;
    static boolean sdreadCardWritePermission;
    static boolean phoneSatePermission;
    static boolean smsSatePermission;
    static boolean creSatePermission;
    static PackageManager pkgManager;


    /**
     * 读写权限
     *
     * @param context
     * @return
     */
    public static boolean getSdPremission(Context context) {
        // 读写 sd card 权限非常重要, android6.0默认禁止的, 建议初始化之前就弹窗让用户赋予该权限
        pkgManager = context.getPackageManager();
        sdCardWritePermission =
                pkgManager.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
        return sdCardWritePermission;
    }

    /**
     * 读权限
     *
     * @param context
     * @return
     */
    public static boolean getSdreadPremission(Context context) {
        // 读写 sd card 权限非常重要, android6.0默认禁止的, 建议初始化之前就弹窗让用户赋予该权限
        pkgManager = context.getPackageManager();
        sdreadCardWritePermission =
                pkgManager.checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
        return sdCardWritePermission;
    }

    /**
     * 相机权限
     *
     * @param context
     * @return
     */
    public static boolean getCrePremission(Context context) {
        // 读写 sd card 权限非常重要, android6.0默认禁止的, 建议初始化之前就弹窗让用户赋予该权限
        pkgManager = context.getPackageManager();
        creSatePermission =
                pkgManager.checkPermission(Manifest.permission.CAMERA, context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
        return sdCardWritePermission;
    }

    /**
     * 读取信息权限
     *
     * @param context
     * @return
     */
    public static boolean getSmsPremission(Context context) {
        pkgManager = context.getPackageManager();
        // read phone state用于获取 imei 设备信息
        smsSatePermission = pkgManager.checkPermission(Manifest.permission.READ_SMS, context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
        return smsSatePermission;
    }

    /**
     * 读取手机设备信息权限
     *
     * @param context
     * @return
     */
    public static boolean getimeiPremission(Context context) {
        pkgManager = context.getPackageManager();
        // read phone state用于获取 imei 设备信息
        phoneSatePermission = pkgManager.checkPermission(Manifest.permission.READ_PHONE_STATE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED;
        return phoneSatePermission;
    }


}
